package com.balad.elements;

import com.balad.services.DataServices;

import android.app.Activity;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;

public class ListeVillesBoutonActivity extends Activity {
    /** Called when the activity is first created. */
    DataServices dataservices;
    boolean ville_is_loaded;
    
    @Override
    public void onCreate(Bundle savedInstanceState) {
	    super.onCreate(savedInstanceState);
	    setContentView(R.layout.accueil);
	    
	    dataservices = (DataServices)getApplicationContext();
    }
    
    public void lancerVille(View view) {
		ville_is_loaded = dataservices.chargerVille(1);
		if (ville_is_loaded){
			Intent intent = new Intent(ListeVillesBoutonActivity.this,VilleActivity.class);
			startActivity(intent);
		} else {
			alertdialogbox();
		}
    }
    
    public void alertdialogbox(){
		AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(ListeVillesBoutonActivity.this);
		// set title
		alertDialogBuilder.setTitle(R.string.AlertDialogTitreAvertissement);

		// set dialog message
		alertDialogBuilder
			.setMessage(R.string.AlertDialogPasDeConnexionVille)
			.setCancelable(false)
			.setPositiveButton(R.string.ok,new DialogInterface.OnClickListener() {
			public void onClick(DialogInterface dialog,int id) {
				// if this button is clicked, close
				// current activity
				dialog.cancel();
			}
		});
		// create alert dialog
		AlertDialog alertDialog = alertDialogBuilder.create();
	
		// show it
		alertDialog.show();	
    }
    
}